package cn.tedu.zhwy.community.service.impl;

import cn.tedu.zhwy.base.response.JsonResult;
import cn.tedu.zhwy.community.mapper.ComplainMapper;
import cn.tedu.zhwy.community.pojo.dto.ComplainParam;
import cn.tedu.zhwy.community.pojo.entity.Complain;
import cn.tedu.zhwy.community.pojo.vo.ComplainVO;
import cn.tedu.zhwy.community.service.ComplainService;
import cn.tedu.zhwy.workspase.mapper.WorkSpaceMapper;
import cn.tedu.zhwy.workspase.pojo.vo.LamdlordVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class ComplainServiceImpl implements ComplainService {
    @Autowired
    ComplainMapper complainMapper;
    @Autowired
    WorkSpaceMapper workSpaceMapper;

    @Override
    public List<ComplainVO> select(ComplainParam complainParam) {
        log.debug("查询投诉信息={}", complainParam);
        log.debug("s{}",complainParam.getLname());
        if (complainParam.getLname()!=null){
            LamdlordVO lamdlordVO = workSpaceMapper.selectbyname(complainParam.getLname());
            complainParam.setClid(lamdlordVO.getLid());
        }
        log.debug("s{}",complainParam.getClid());
        List<ComplainVO> list = complainMapper.select(complainParam);
        log.debug("查询投诉信息完成，结果={}", list);
        return list;
    }

    @Override
    public void update(ComplainParam complainParam) {
        log.debug("修改投诉信息={}", complainParam);
        Complain complain=new Complain();
        BeanUtils.copyProperties(complainParam,complain);
        if (complain.getCid()!=null){
            complainMapper.update(complain);
        }
    }

    @Override
    public void delete(Integer cid) {
        complainMapper.delete(cid);
        log.debug("删除投诉信息完成，结果={}", cid);
    }
}
